<?php
namespace app\web\controller;

use app\web\model\Vocation;
use think\Db;

class Index extends Base
{
    public function index()
    {
      $vocation = new Vocation();
      //独家项目
      $sole = $vocation->where('sole','=',1)->limit(2)->order('id desc')->select();
      $this->assign('sole',$sole);
      //热门城市
      $city = Db::name('address')->limit(8)->select();
      $this->assign('city',$city);
      //热门工作分类（侧边导航）
      $navOne = Db::name('vocation')->order('id asc')->where('type','=',1)->limit(5)->select();  //国内
      $navTwo = Db::name('vocation')->order('id asc')->where('type','=',2)->limit(5)->select();  //国外
      $this->assign(array(
        'navOne' => $navOne,
        'navTwo' => $navTwo
      ));
      //热门工作
      $workInt = $vocation::with('work')->order('id asc')->where('type','=',1)->select(); //国内
      $workOut = $vocation::with([
        'work'=>function($query){
          $query->limit(3);
        }
      ])->order('id asc')->where('type','=',2)->select(); //国外
      $this->assign(array(
        'workInt' => $workInt,
        'workOut' => $workOut
      ));
      //出国知识
      $cgzz = Db::name('article')->where('cate_id','=',1)->paginate(10);
      $this->assign('cgzz',$cgzz);
      return view();
    }
}